<!--#include file="common/header.html"-->
<body>
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">
            <!--头部搜索-->
            <section class="panel panel-padding">
                <form class="layui-form" action="/education/admin/comment">
                    <div class="layui-form">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input class="layui-input" name="_query.keyword" placeholder="关键字">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button lay-submit class="layui-btn" lay-filter="search" id="search">查找</button>
                        </div>
                    </div>
                </form>
            </section>

            <!--列表-->
            <section class="panel panel-padding">
                <div class="group-button">
                    <!--<button class="layui-btn layui-btn-small modal-catch"
                            data-params='{"content":".add-subcat", "title":"导入","type":"1", "full":"true", "maxmin":"true"}'>
                        <i class="iconfont">&#xe649;</i> 导入
                    </button>-->
                    <button class="layui-btn layui-btn-small layui-btn-danger ajax-all" data-name="checkbox" data-params='{"url": "/education/admin/comment/delete"}'>
                        <i class="iconfont">&#xe626;</i> 删除
                    </button>
                </div>
                <div id="list" class="layui-form"></div>

                <div class="text-right" id="page"></div>
            </section>
        </div>
    </div>
</div>

<div class="add-subcat">
    <form class="layui-form layui-form-pane" method="post"
          action="/education/admin/import/comment" id="form1"  enctype="multipart/form-data" >
        <input type="hidden" name="id">

        <div class="layui-form-item">
           <!-- <label class="layui-form-label">选择文件</label>-->
            <div class="layui-input-inline">
                <input type="file" name="file">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="submit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

</body>
<script id="list-tpl" type="text/html"
        data-params='{"url":"/education/admin/comment","dataName":"commentData","pageid":"#page", "method":"post","data":"orderColunm=a.create_time&orderMode=desc"}'>
    <table id="example" class="layui-table lay-even" data-name="commentData" data-tplid="list-tpl">
        <thead>
        <tr>
            <th width="30"><input type="checkbox" id="checkall" data-name="checkbox" lay-filter="check"
                                  lay-skin="primary"></th>
            <th>商品名</th>
            <th>评价内容</th>
            <th>图片</th>
            <th>几颗星</th>
            <th width="100">APP显示</th>
            <th>评价人</th>
            <th>评价时间</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody>
        {{# layui.each(d.list, function(index, item){ }}
        <tr>
            <td><input type="checkbox" name="checkbox" value="{{ item.id}}" lay-skin="primary"></td>
            <td>{{ item.product_name }}</td>
            <td>{{ item.comment_content }}</td>
            <td>
                <div class="layer-photos-demo">
                    {{# var imgs = item.comment_images && item.comment_images.split(',')  }}
                    {{# if(imgs) { }}
                    {{# for(var i=0;i< imgs.length; i++){ }}
                    <img layer-src="/education{{ imgs[i] }}"  src="/education{{ imgs[i] }}"
                         onclick="viewImg();"
                         style="height:60px;"  alt="图片">
                    {{# } } }}
                </div>
            </td>
            <td>
                {{# for(var i=1;i<= item.star;i++){ }}
                <!--<img src="../../jqadmin/images/star_1.png" style="height: 30px;">-->
                <i class="iconfont color-yellow" style="font-size: 1px;">&#xe61f;</i>
                {{# } }}
            </td>
            <td><input type="checkbox" name="comment_status" lay-skin="switch" lay-text="显示|隐藏"
                       {{#if (item.comment_status == 1){ }}checked="checked" {{# } }} lay-filter="ajax" value="1"
                       data-params='{"url":"/education/admin/comment/update/{{ item.id}}","data":"id={{ item.id}}"}'>
            </td>
            <td>{{ item.comment_username||''}}</td>
            <td>{{ formatDate(item.create_time)}}</td>
            <td>
                <!--<button class="layui-btn layui-btn-mini layui-btn-danger ajax"
                        data-list='{"key":"id={{ item.id}}","msg":true,"render":"true","action":"del"}'
                        data-params='{"url": "/education/admin/comment/delete/{{item.id}}","data":"", "method":"post", "confirm":"true"}'>
                    <i class="iconfont">&#xe626;</i>删除
                </button></td>-->
                <div class="tab-menu layui-btn layui-btn-mini">
                    <a href="javascript:;" data-url="module/order-view.html?orderId={{item.order_id}}"
                       data-parent="true"
                       data-title="订单详情">
                        <span style="color: white">订单详情</span>
                    </a>
                </div>
            </td>
        </tr>
        {{# }); }}
        </tbody>

    </table>
</script>
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../../jsfile/jquery/jquery.form.js"></script>
<!--#include file="common/version.html"-->
<script>
    layui.use('user_list');

    function afterTableLoad(data) {
        layui.use(['jquery', 'jqmenu'], function(exports) {
            var jqmenu = layui.jqmenu;
            var menu = new jqmenu();
            menu.options.isFresh = true
            menu.menuBind();
        });
    }

    $(document).ready(function() {
        $("#form1").ajaxForm({
            dataType: "json"
            , success: function(data) {
                layer.msg('导入成功' + rs.data + '条');
                console.log("成功",rs)
            }
            , error: function(ret) {
                layer.msg('导入失败');
                console.log("错误")
            }
        });
    });

    function initData(){
        var $v = '{"url":"/education/admin/comment?_query.productId='+ getQueryString('ids')
            +'","dataName":"commentData","pageid":"#page", "method":"post", "data":"orderColunm=a.create_time&orderMode=desc"}';
        $("#list-tpl").attr('data-params', $v);
    }

    function viewImg() {
        layui.use('layer', function(){
            var layer = layui.layer;
            layer.photos({
                photos: '.layer-photos-demo'
                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
            });
        });
    }

    function beforeAdd(obj){
        $('.imgbox').children().remove();
        $('#form1').attr('action', '/education/admin/comment/save');
    }

    function submitForm() {
        var pid = getQueryString('ids');
        $('#pid').val(pid);
        restInsert('/education/admin/comment/save', {}, $('#form1'), function (rs) {
            if(rs.status == 200){
                layer.close(layer.index);
//                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
//                parent.layer.close(index); //再执行关闭
                layer.msg('操作成功');
                $('#search').trigger('click')
            }
        })
    }

    function formatDate(date) {
        if(date == null){
            return '';
        }
        return date && date.substring(0, 16);
    }
</script>

</html>